#include "global.h"
#include "GlobalEvtHandler.h"

        wxTextCtrl* GlobalEvtHandler::startterm;
        wxHtmlWindow * GlobalEvtHandler::ls36html;
        wxString GlobalEvtHandler::CurrentPAGE;
         long GlobalEvtHandler::pageIndex=0;
         long GlobalEvtHandler::totalPage=0;
            wxHtmlPrintout* GlobalEvtHandler::printer;
            wxHtmlPrintout* GlobalEvtHandler::watch;
//toolbar history search
 wxComboBox*	 GlobalEvtHandler::m_comboBox1;
 wxComboBox*	 GlobalEvtHandler::m_comboBox2;
 wxComboBox*	 GlobalEvtHandler::m_comboBox3;
 wxComboBox*	 GlobalEvtHandler::m_comboBox4;
 wxComboBox*	 GlobalEvtHandler::m_comboBox5;
 wxComboBox*	 GlobalEvtHandler::m_comboBox6;
 wxComboBox*	 GlobalEvtHandler::blue_combobox;
 wxComboBox*	 GlobalEvtHandler::termlist;
 wxTextCtrl * GlobalEvtHandler::termrange;//分析期数

 wxCheckBox*   GlobalEvtHandler::positionStrict;
 wxComboBox*   GlobalEvtHandler::watchNext;
 wxHtmlWindow* GlobalEvtHandler::historywin;


  wxStaticText*  GlobalEvtHandler::infolabel;
 wxStaticText*  GlobalEvtHandler::book1infolabel;
 //add for 对偶数
 wxTextCtrl * GlobalEvtHandler::endmatch;
 wxTextCtrl * GlobalEvtHandler::startmatch;
 //another UI
 wxComboBox*	 GlobalEvtHandler::h_comboBox1;
 wxComboBox*	 GlobalEvtHandler::h_comboBox2;
 wxComboBox*	 GlobalEvtHandler::h_comboBox3;
 wxComboBox*	 GlobalEvtHandler::h_comboBox4;
 wxComboBox*	 GlobalEvtHandler::h_comboBox5;
 wxComboBox*	 GlobalEvtHandler::h_comboBox6;
 wxComboBox*	 GlobalEvtHandler::h_blue_combobox;
 wxComboBox*	 GlobalEvtHandler::h_termlist;
 wxCheckBox*     GlobalEvtHandler::h_positionStrict;
 wxComboBox*     GlobalEvtHandler::h_watchNext;
 wxHtmlWindow*   GlobalEvtHandler::h_historywin;
 wxCheckBox* GlobalEvtHandler::h_follow;
 wxTextCtrl* GlobalEvtHandler::searchstartterm;//search ui start term

wxTextCtrl* GlobalEvtHandler::sqltext;

 wxDialog* GlobalEvtHandler::h_dialog=NULL;//dialog proxy
 int GlobalEvtHandler::PageSize=15;

redBallHM GlobalEvtHandler::book1terms;

GlobalEvtHandler::GlobalEvtHandler()
{
   pageIndex=0;
}

GlobalEvtHandler::~GlobalEvtHandler()
{
   pageIndex=0;
totalPage=0;

}
/*
各种算法预测号码的分析
*/
   wxWindow* GlobalEvtHandler::book1MultiThread(wxWindow* parent)
   {
        int width=BFrame->GetVirtualSize().GetWidth();
        int height=BFrame->GetVirtualSize().GetHeight();

    wxPanel* first  = new wxPanel(parent,wxID_ANY,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL|wxBORDER_RAISED);
    book1terms = getTermList();
    wxArrayString sortTerm;
//    forecast.Sort(false);

    wxString nextTerm=getLastTermOrder();
    sortTerm.Add(nextTerm);
    wxTextValidator validator(wxFILTER_NUMERIC);

    GlobalEvtHandler::termlist = new wxComboBox(first, wxID_ANY, wxEmptyString,  wxPoint(0,0),wxSize(80,30),0,NULL, 0  ,validator);


    termlist->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED,wxCommandEventHandler(GlobalEvtHandler::comboboxSelected));

    book1infolabel = new wxStaticText(first, wxID_ANY, wxT("                    "), wxPoint(85,0), wxDefaultSize, wxBORDER_DOUBLE  );
    book1infolabel->SetForegroundColour(*wxRED);

    wxStaticText* label1=new wxStaticText(first, wxID_ANY, wxT("分析期数"), wxPoint(360,0), wxDefaultSize);
        label1->SetForegroundColour(*wxRED);

    GlobalEvtHandler::termrange = new wxTextCtrl(first, wxID_ANY, wxEmptyString, wxPoint(420,0), wxSize(80,20));
    termrange->SetValue(wxT("55"));


    redBallHM::iterator  it;

     for(it =book1terms.begin();it != book1terms.end(); ++it )
    {
       sortTerm.Add(it->first);
    }
    sortTerm.Sort(true);
    //下拉
    for(int i=0;i<sortTerm.GetCount();i++)termlist->Append(sortTerm.Item(i));

     termlist->SetSelection(0);
    //wxCB_READONLY
    wxButton *AI1 = new wxButton(first, -1, wxT("三期为重点\n形状分析"),wxPoint(0,30));
   // AI1->Connect(wxEVT_LEFT_DOWN, wxCommandEventHandler(GlobalEvtHandler::startAIAction));
    AI1->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::startAIAction));

      int ht=BFrame->GetToolBar()->GetToolSize().GetHeight();
      int yc=30+30;
     int size=first->GetSize().GetWidth();

    wxStaticLine*  line=new wxStaticLine(first,wxID_ANY, wxPoint(0,yc+20),wxSize(1024,2),wxLI_HORIZONTAL,wxT("分析方法"));
    wxStaticText* desc =new wxStaticText(first,wxID_ANY,wxT("预测数字:"),wxPoint(0,yc+15),wxDefaultSize,wxALIGN_LEFT );
	desc->SetFont( wxFont(12, wxFONTFAMILY_DEFAULT ,wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD , false, wxT("simsun") ) );
	desc->SetForegroundColour(*wxRED);
	BFrame->AIActionWatchTextBox=new wxTextCtrl(first, ID_WATCH_WINDOW, wxT(""),
                            wxPoint(10,115), wxSize(width-64-45,height-100),
                             wxTE_MULTILINE |wxHSCROLL|wxTE_AUTO_URL   /* | wxTE_RICH */);
     BFrame->AIActionWatchTextBox->SetDefaultStyle(wxTextAttr(*wxBLUE, *wxWHITE, *wxNORMAL_FONT));
     return first;
   }
 /*
 历史数据维护页面
 */
   wxWindow* GlobalEvtHandler::book1InputHistorySQL(wxWindow* parent)
   {
   wxPanel* second=new wxPanel(parent);
   int width,height;
   BFrame->GetVirtualSize(&width,&height);
//   wxMessageBox(wxString::Format(wxT("%02d,%02d"),width,height));
    wxHtmlWindow * html = new wxHtmlWindow(second, wxID_ANY, wxPoint(10,5),  wxSize(580,50), wxHW_SCROLLBAR_NEVER|wxBORDER_RAISED );
    wxButton * updateFromWebSite =new wxButton(second,wxID_ANY,wxT("网络更新数据..."),wxPoint(600,30));
    updateFromWebSite->SetForegroundColour(*wxRED);
    updateFromWebSite->Connect(wxEVT_LEFT_DOWN, wxCommandEventHandler(GlobalEvtHandler::InternetUpdate));

    html->SetBackgroundColour(wxColour(wxT("wxLIGHT_GREY")));
    wxString nextterm=getLastTermOrder();
    //wxString nextterm=getNextTermOrder(lastterm);
    //last weekday
    wxString lastdate=getLastTermDate();
      wxDateTime fdt;
     fdt.ParseDate(lastdate.c_str());
     wxString week=wxT(" (")+fdt.GetWeekDayName(fdt.GetWeekDay())+wxT(")");
     //next weekday
     wxString nextdate=getNextTermDate(lastdate);
     fdt.ParseDate(nextdate.c_str());
     wxString nextweek=fdt.GetWeekDayName(fdt.GetWeekDay());
   wxDateTime now=wxDateTime::UNow();
   wxString alert=wxEmptyString;
   fdt.ParseDate(lastdate.c_str());
   wxTimeSpan diff = now.Subtract(fdt);
     if(diff.GetDays()>3)alert=wxT("<font color=red><u>(数据需要更新了!)<u></font>");
    wxString pages=wxT("<table valign=top CELLSPACING=0 CELLPADDING=0>")
                   wxT("<tr><td align=right><font color=red ><b>数据库最后一期:</font></td><td align=left><font color=blue>")+wxString::FromAscii(DoubleBall::_LastTermOrder)+wxT("</td><td>:")+week+wxT("</font></b><font color=red>(")+wxString::FromAscii(DoubleBall::_LastTermDate)+wxT(")</td></tr>")
                   wxT("<tr><td align=right><font color=red ><b>下一期:</b></font>")+wxT("</td><td align=left><font color=blue><b>")+nextterm+wxT("</b></font><font color=red></td><td>:(")+nextweek+wxT(")(")+nextdate+wxT(")")+alert+wxT("</font></td></tr>")
                   wxT("</table>");
    html->SetPage(pages);

    BFrame->SQLTextBox=new wxTextCtrl(second, wxID_ANY, wxT(""),
                            wxPoint(10,60), wxSize(400,getScreenHeight()-250),
                             wxTE_MULTILINE | wxTE_AUTO_URL|wxHSCROLL  /* | wxTE_RICH */);
    BFrame->SQLTextBox->SetDefaultStyle(wxTextAttr(*wxBLUE, *wxWHITE, *wxNORMAL_FONT));
  //add second wxhtmlWindow
     BFrame->sqlhtml = new wxHtmlWindow(second, wxID_ANY, wxPoint(420,60), wxSize(280,getScreenHeight()-250), wxHW_SCROLLBAR_AUTO |wxBORDER_RAISED );
    BFrame->sqlhtml->SetBackgroundColour(wxColour(wxT("wxLIGHT_GREY")));

    long  textokid= wxNewId();

    wxButton *textok = new wxButton(second,textokid, wxT("确定"), wxPoint((10+400)/2-5,(getScreenHeight()-200)+20));
    textok->Connect(wxEVT_LEFT_DOWN, wxCommandEventHandler(bonusFrame::inputSQL));
    return second;
   }
  /*
  book1 增加
  */
   wxWindow* GlobalEvtHandler::book1LS36(wxWindow* parent)
   {
    wxPanel* books=new wxPanel(parent,wxID_ANY,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL|wxWANTS_CHARS);
    /**********************add 过滤栏********************************/
    wxTextValidator validator(wxFILTER_NUMERIC);
    int y=5;

    GlobalEvtHandler::m_comboBox1 = new wxComboBox( books, wxID_ANY, wxEmptyString, wxPoint(10,y), wxSize(40,30), 34, REDBALLS, 0  ,validator);
 	GlobalEvtHandler::m_comboBox2 = new wxComboBox( books, wxID_ANY, wxEmptyString, wxPoint(50,y), wxSize(40,30), 34, REDBALLS, 0  ,validator);
	GlobalEvtHandler::m_comboBox3 = new wxComboBox( books, wxID_ANY, wxEmptyString, wxPoint(90,y), wxSize(40,30), 34, REDBALLS, 0  ,validator);
	GlobalEvtHandler::m_comboBox4 = new wxComboBox( books, wxID_ANY, wxEmptyString, wxPoint(130,y), wxSize(40,30), 34, REDBALLS, 0  ,validator);
	GlobalEvtHandler::m_comboBox5 = new wxComboBox( books, wxID_ANY, wxEmptyString, wxPoint(170,y), wxSize(40,30), 34, REDBALLS, 0  ,validator);
	GlobalEvtHandler::m_comboBox6 = new wxComboBox( books, wxID_ANY, wxEmptyString, wxPoint(210,y), wxSize(40,30), 34, REDBALLS, 0  ,validator);//wxCB_READONLY
//blue
	GlobalEvtHandler::blue_combobox = new wxComboBox( books, wxID_ANY, wxEmptyString, wxPoint(260,y), wxSize(40,30), 17, BLUEBALLS, 0  ,validator);

GlobalEvtHandler::positionStrict = new wxCheckBox(books,wxID_ANY,wxT("红球位置对应"),wxPoint(300,y-5));
 positionStrict->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));

GlobalEvtHandler::positionStrict->SetForegroundColour(*wxRED);
GlobalEvtHandler::watchNext = new wxComboBox(books,wxID_ANY,listStype[0],wxPoint(300,y+8),wxSize(80,30),3,listStype,NULL);
GlobalEvtHandler::watchNext->SetEditable(false);
GlobalEvtHandler::watchNext->SetForegroundColour(*wxRED);

watchNext->Connect(wxEVT_COMMAND_COMBOBOX_SELECTED,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));

wxButton*	searchButton  = new wxButton( books,  wxID_ANY,  wxT("查询..."),wxPoint(440,y));
infolabel = new wxStaticText( books, wxID_ANY, wxT("          "), wxPoint(520,y), wxDefaultSize, wxSUNKEN_BORDER );
infolabel->SetForegroundColour(*wxRED);

searchButton->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));

GlobalEvtHandler::m_comboBox1->SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxFONTWEIGHT_BOLD, 0, wxT("Sans")));
GlobalEvtHandler::m_comboBox2->SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxFONTWEIGHT_BOLD, 0, wxT("Sans")));
GlobalEvtHandler::m_comboBox3->SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxFONTWEIGHT_BOLD, 0, wxT("Sans")));
GlobalEvtHandler::m_comboBox4->SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxFONTWEIGHT_BOLD, 0, wxT("Sans")));
GlobalEvtHandler::m_comboBox5->SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxFONTWEIGHT_BOLD, 0, wxT("Sans")));
GlobalEvtHandler::m_comboBox6->SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxFONTWEIGHT_BOLD, 0, wxT("Sans")));
GlobalEvtHandler::blue_combobox->SetFont(wxFont(10, wxDEFAULT, wxNORMAL, wxFONTWEIGHT_BOLD, 0, wxT("Sans")));
GlobalEvtHandler::m_comboBox1->SetForegroundColour(*wxRED);
GlobalEvtHandler::m_comboBox2->SetForegroundColour(*wxRED);
GlobalEvtHandler::m_comboBox3->SetForegroundColour(*wxRED);
GlobalEvtHandler::m_comboBox4->SetForegroundColour(*wxRED);
GlobalEvtHandler::m_comboBox5->SetForegroundColour(*wxRED);
GlobalEvtHandler::m_comboBox6->SetForegroundColour(*wxRED);
GlobalEvtHandler::blue_combobox->SetForegroundColour(*wxBLUE);

    /***********************结束************************************/

     y=29+10;

    wxButton *first = new wxButton(books,ID_BUTTON_FIRSTPAGE, wxT("|<第一页"), wxPoint(10,y));
    int x=10+first->GetRect().GetX()+first->GetDefaultSize().GetWidth();
    wxButton *post  = new wxButton(books,ID_BUTTON_FORM_PAGE, wxT("<<上一页"), wxPoint(x,y));

     x=10+post->GetRect().GetX()+ post->GetDefaultSize().GetWidth();
    wxButton *next  = new wxButton(books,ID_BUTTON_NEXT_PAGE, wxT("下一页>>"), wxPoint(x,y));

     x=10+next->GetRect().GetX()+ next->GetDefaultSize().GetWidth();
    wxButton *last  = new wxButton(books,ID_BUTTON_LAST_PAGE, wxT("最后页>|"), wxPoint(x,y));

      x=10+last->GetRect().GetX()+ last->GetDefaultSize().GetWidth();
     //add startterm indicator
     startterm= new wxTextCtrl(books,wxID_ANY,wxEmptyString,wxPoint(x,y),wxSize(80,last->GetDefaultSize().GetHeight()),wxTE_LEFT);
     startterm->SetDefaultStyle(wxTextAttr(*wxRED));
     //add print button
      x=10+startterm->GetRect().GetX()+ startterm->GetSize().GetWidth();

      wxButton *print  = new wxButton(books,ID_BUTTON_PRINT_PAGE, wxT("打印..."), wxPoint(x,y));
      //add copy clipboard
      x=10+print->GetRect().GetX()+ print->GetSize().GetWidth();
      wxButton *toclip  = new wxButton(books,ID_BUTTON_TO_CLIP, wxT("复制剪贴板"), wxPoint(x,y));


     first->Connect(wxEVT_COMMAND_BUTTON_CLICKED ,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));
     post->Connect(wxEVT_COMMAND_BUTTON_CLICKED ,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));
     next->Connect(wxEVT_COMMAND_BUTTON_CLICKED ,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));
     last->Connect(wxEVT_COMMAND_BUTTON_CLICKED ,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));

     first->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));
     post->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));
     next->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));
     last->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));

     print->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnPagePrintHandler));
      toclip->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnCopytoClipBoardHander));

    print->Connect(wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(GlobalEvtHandler::OnPagePrintHandler));
    toclip->Connect(wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(GlobalEvtHandler::OnCopytoClipBoardHander));

      this->ls36html = new wxHtmlWindow(books, wxID_ANY, wxPoint(10,y+35), wxSize(getScreenWidth()-120,getScreenHeight()-170-y), wxHW_SCROLLBAR_AUTO |wxBORDER_RAISED );
      this->ls36html->SetPage(wxT("<html><body><h1>输入起始期号,否则显示全部</h1></body></html>"));
    return books;
   }

  /*
  book4 ecl ai
  */
   wxWindow* GlobalEvtHandler::book1Database(wxWindow* parent)
   {
    wxPanel* books=new wxPanel(parent,wxID_ANY,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL|wxWANTS_CHARS);
int width=BFrame->GetVirtualSize().GetWidth();
int height=BFrame->GetVirtualSize().GetHeight();
int x=5,y=5;
wxButton*	Button1  = new wxButton( books,  wxID_ANY,  wxT("查询..."),wxPoint(x,y));
//testECL
x=x+75;
wxButton*	Button2  = new wxButton( books,  wxID_ANY,  wxT("ECL Testing"),wxPoint(x,y));
x=x+80;
wxButton*	Button3  = new wxButton( books,  wxID_ANY,  wxT("红球出现数字间隔"),wxPoint(x,y));
x=5;
y=y+40;
wxButton*	Button4  = new wxButton( books,  wxID_ANY,  wxT("输出LISP文件"),wxPoint(x,y));

Button1->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnPagingHandler));
Button2->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnECLHandler));
Button3->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnRedBallDistanceHandler));
Button4->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnExportECLFileHandler));
x=5;
y=y+40;
//label code
wxStaticText *label1 = new wxStaticText(books, wxID_ANY, wxT("代码:"),wxPoint(x,y),wxSize(80,20));
    label1->SetForegroundColour(*wxRED);
wxButton*	ButtonSave  = new wxButton( books,  wxID_ANY,  wxT("保存"),wxPoint(x+80+20,y));
wxButton*	ButtonDel   = new wxButton( books,  wxID_ANY,  wxT("删除"),wxPoint(x+80+20+80,y));
ButtonSave->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnLISPSaveHandler));
ButtonDel->Connect(wxEVT_LEFT_DOWN,wxCommandEventHandler(GlobalEvtHandler::OnLISPDelHandler));

y=y+25;
//code text
    BFrame->LISPCodeBox=new wxTextCtrl(books, wxID_ANY, wxT(""),
                            wxPoint(x,y), wxSize(400,getScreenHeight()-250-20),
                             wxTE_MULTILINE | wxTE_AUTO_URL|wxHSCROLL  /* | wxTE_RICH */);
    BFrame->LISPCodeBox->SetDefaultStyle(wxTextAttr(*wxBLUE, *wxWHITE, *wxNORMAL_FONT));
x=x+410;
//add title
y=y-20;
wxStaticText *label = new wxStaticText(books, wxID_ANY, wxT("代码名字必须输入："),wxPoint(x,y),wxSize(400,20));
    label->SetForegroundColour(*wxRED);

y=y+20;
BFrame->LISPCodeName = new wxTextCtrl(books, wxID_ANY, wxT(""),
                            wxPoint(x,y),wxSize(400,20));

y=y+20;
  //add second wxhtmlWindow
     BFrame->lisphtml = new wxHtmlWindow(books, wxID_ANY, wxPoint(x,y), wxSize(400,getScreenHeight()-250-40), wxHW_SCROLLBAR_AUTO |wxBORDER_RAISED );
     BFrame->lisphtml->SetBackgroundColour(wxColour(wxT("wxLIGHT_GREY")));
DoubleBall* db =new DoubleBall();
wxString SQL =wxT("select * from _LISPLET order by createdate desc");
db->query(SQL.char_str());
wxString pages = formatLISPtoHTML(db);

 pages=wxT("<html><meta http-equiv='Content-Type' content='text/html; charset=gb2312' /><body>汉字<br/>")+pages+wxT("</body></html>");
 BFrame->lisphtml->SetPage(pages);
 delete db;
    return books;
   }
/*
book3
*/

void GlobalEvtHandler::OnPagingHandler(wxCommandEvent& event)
{
    wxString begin=startterm->GetValue();

     /**************6 个红球处理****************/
wxString insm=wxT(" in (red1,red2,red3,red4,red5,red6) ");
wxString where=wxEmptyString;
wxString redballwhere=wxEmptyString;
wxString withNextWhere=wxEmptyString;
wxString sqllist1=wxEmptyString;
wxString sqllist2=wxEmptyString;
wxString sqllist3=wxEmptyString;

if(positionStrict->IsChecked())
{
 if(m_comboBox1->GetValue()!=wxEmptyString)redballwhere= wxT(" red1=")+m_comboBox1->GetValue();
 if(m_comboBox2->GetValue()!=wxEmptyString)redballwhere=redballwhere+ (redballwhere!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" red2=")+m_comboBox2->GetValue();
 if(m_comboBox3->GetValue()!=wxEmptyString)redballwhere=redballwhere+ (redballwhere!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" red3=")+m_comboBox3->GetValue();
 if(m_comboBox4->GetValue()!=wxEmptyString)redballwhere=redballwhere+ (redballwhere!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" red4=")+m_comboBox4->GetValue();
 if(m_comboBox5->GetValue()!=wxEmptyString)redballwhere=redballwhere+ (redballwhere!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" red5=")+m_comboBox5->GetValue();
 if(m_comboBox6->GetValue()!=wxEmptyString)redballwhere=redballwhere+ (redballwhere!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" red6=")+m_comboBox6->GetValue();
 if(blue_combobox->GetValue()!=wxEmptyString)redballwhere=redballwhere+  (redballwhere!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" blue=")+blue_combobox->GetValue();

}else
{
 wxString select=wxEmptyString;

 if(m_comboBox1->GetValue()!=wxEmptyString)select=m_comboBox1->GetValue()+insm;
 if(m_comboBox2->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+m_comboBox2->GetValue()+insm;
 if(m_comboBox3->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+m_comboBox3->GetValue()+insm;
 if(m_comboBox4->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+m_comboBox4->GetValue()+insm;
 if(m_comboBox5->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+m_comboBox5->GetValue()+insm;
 if(m_comboBox6->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+m_comboBox6->GetValue()+insm;
  redballwhere= select;
 if(blue_combobox->GetValue()!=wxEmptyString)redballwhere=redballwhere+  (redballwhere!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" blue=")+blue_combobox->GetValue();
}


/*******************************************************/
   DoubleBall* db=new DoubleBall();
  wxString SQL=wxT("select * from _DBHISTORY ");
  wxString filter=wxEmptyString;
 if(begin!=wxEmptyString)filter=wxT("  cast(term as int)>=")+begin;
where =redballwhere;
if(redballwhere!=wxEmptyString)//包含下一期的完整SQL
{
 withNextWhere=wxT("  rowid in (select rowid+1 as rowid from _DBHISTORY where ")
        +redballwhere+(filter!=wxEmptyString? wxT(" and ")+filter:wxT(""))+wxT(")");
  SQL=SQL+ wxT(" where ")+redballwhere +wxT(" union ")+wxT("select * from _DBHISTORY where ")+withNextWhere;
}else//红球不需要过滤
{
 SQL=SQL+(filter!=wxEmptyString?wxT(" where ")+filter:wxT(""));
}
//check显示模式
if(watchNext->GetValue()==listStype[1]) //列表方式
{
    PageSize=33;

}else if(watchNext->GetValue()==listStype[0]) //幻方方式

{
    PageSize=15;
}else if(watchNext->GetValue()==listStype[2])//HTMLgrid方式
{
  PageSize=33;
}
        if(redballwhere!=wxEmptyString)
        {
         sqllist1=wxT("select * from _DBHISTORY where ")+withNextWhere;
         sqllist2=wxT("select * from _DBHISTORY where ")+redballwhere+(filter!=wxEmptyString? wxT(" and ")+filter:wxT(""));
         SQL=sqllist2+wxT(" union all ")+sqllist1 +wxT("  order by term asc ");
 //   ::wxGetTextFromUser(wxEmptyString,wxEmptyString,SQL);
         }else
        {
         sqllist3=wxT("select * from _DBHISTORY ")+(filter!=wxEmptyString?wxT(" where ")+filter:wxT(""));
         SQL=sqllist3;
        }
//for total page
  db->query((SQL).char_str());
  BFrame->SetStatusText(wxT("当前SQL:")+SQL);
  totalPage=((db->nrow+PageSize)/PageSize)-1;
   if(pageIndex>totalPage)pageIndex=0;

  //set totoal records
  switch(event.GetId())
   {
    case ID_BUTTON_FIRSTPAGE:pageIndex=0;break;
    case ID_BUTTON_FORM_PAGE:pageIndex=(pageIndex>0?pageIndex-1:0);break;
    case ID_BUTTON_NEXT_PAGE:
        if(pageIndex+1>totalPage)
          {
          }else
          {
//           ((wxButton*)event.GetEventObject())->Enable(true);
          pageIndex=pageIndex+1;
          }
         break;
    case ID_BUTTON_LAST_PAGE:pageIndex=totalPage;break;
   }
  infolabel->SetLabel(wxString::Format(wxT("%05d 条记录,%02d/%02d页"),db->nrow-1,pageIndex+1,totalPage+1));

  wxString limit =wxT(" limit ")+wxString::Format(wxT("%02d"),pageIndex*PageSize)+wxT(",")+wxString::Format(wxT("%02d"),PageSize);
//for paging and last，主要和下一期混合起来显示
//可以考虑加一个选项来控制是否混合

   SQL=SQL+limit;

   CurrentPAGE=wxT("<html><body>");
if(watchNext->GetValue()==listStype[1]) //列表方式
{
wxString result1=wxEmptyString;
wxString result2=wxEmptyString;
wxString sqlt=wxEmptyString;

        if(redballwhere!=wxEmptyString)//红球有过滤
        {
         sqlt=sqllist1+limit;
         db->query(sqlt.char_str());
        result2=formatDBtoHTML(db,true);
        // ::wxGetTextFromUser(wxEmptyString,wxEmptyString,sqlt);
         sqlt=sqllist2+limit;
        db->query(sqlt.char_str());
        result1=formatDBtoHTML(db,true);
        // ::wxGetTextFromUser(wxEmptyString,wxEmptyString,sqlt);
         }else
{
  sqlt=SQL;
//::wxGetTextFromUser(wxEmptyString,wxEmptyString,sqlt);
db->query(sqlt.char_str());
result1=formatDBtoHTML(db);
}
CurrentPAGE= CurrentPAGE+
                    wxT("<table><tr>")
                    wxT("<td valign=top>")+result1+wxT("</td>")
                    wxT("<td valign=top>")+result2+wxT("</td>")
                    +wxT("</tr></table>");

}else if(watchNext->GetValue()==listStype[0])
{

  db->query(SQL.char_str());
CurrentPAGE=CurrentPAGE+formatDB2LUOSHU36(db,PageSize);

}else if(watchNext->GetValue()==listStype[2])//htmlGrid style
{
     db->query(SQL.char_str());
 CurrentPAGE=CurrentPAGE+formatDBtoHTMLGrid(db,PageSize);

}

//添加下一期过滤
wxString additional=wxEmptyString;
wxString tmp=wxEmptyString;
Statistics* result;
if(redballwhere!=wxEmptyString)
{
debug(sqllist1+limit);
db->query((sqllist1).char_str());
result=statisticsRecords(db);
additional=arrary2string(&result->numberCount[0],MAXREDBALL);
tmp.Printf(wxT("<font color=red><b>最小数:%02i,最大数:%02i </b></font>"),result->min,result->max);
}
delete db;
wxString finalstr=wxT("<table><tr><td width=100%>")+CurrentPAGE+wxT("</td></tr>")
+(redballwhere==wxEmptyString?wxT(""):
wxT("<tr><td colspan=35 width=100%>")+tmp+wxT("<br><font color=green><b>各个数字出现频率统计:</b></font>")
+additional
+wxT("<br><font color=red>红球出现频率统计:</font>")+arrary2string(&result->numberCount[0],MAXREDBALL)
+wxT("<br><b><font color=blue>篮球出现频率统计:</font></b>")+arrary2string(&result->numberBlueCount[0],MAXBLUEBALL)
+wxT("<br><font color=green><b>红球最大位置出现频率统计:</b></font>")
+arrary2string(&result->numberMaxCount[0],MAXREDBALL)+wxT("<br><font color=green><b>红球最小位置出现频率统计:</b></font>")
+arrary2string(&result->numberMinCount[0],MAXREDBALL)+wxT("<br>")
+wxT("</td></tr>")
+wxT("<tr><td colspan=35 >")
+wxT("<br><font color=green>连续数字:<b>")+hashmap2html(result->continuum)+wxT("</b></font>")
+wxT("</td></tr>")
)
+wxT("</table></body></html>");
//::wxGetTextFromUser(wxEmptyString,wxEmptyString,finalstr);
CurrentPAGE=wxT("<html><body>")+finalstr;
ls36html->SetPage(finalstr);
//::wxGetTextFromUser(wxEmptyString,wxEmptyString,CurrentPAGE);
BFrame->_CLIPBOARD=CurrentPAGE;
}


void GlobalEvtHandler::OnECLHandler(wxCommandEvent& event)
{
//testECL();
}
//输出文件LISP
void GlobalEvtHandler::OnExportECLFileHandler(wxCommandEvent& event)
{
 DoubleBall* db=new DoubleBall();
  wxString SQL=wxT("select * from _DBHISTORY order by term asc ");
  db->query((SQL).char_str());
  wxString result=wxEmptyString;
  result=wxT("(defvar *DOUBLEBALL*)\n");
  result=result+wxT("(setf *DOUBLEBALL* (vector ");
  for(int i=1;i<=db->nrow;i++)//第一行为列名
  {
    result=result+wxT("'(");
    for(int j=0;j<=db->ncol-1;j++)//去掉最后一列0
        {
       // value = atoi(db->records[i*db->ncol+j]);
        result=result+wxString::Format(wxT("%d "),atoi(db->records[i*db->ncol+j]));
        }
result=result+wxT(") \n");
  }
  result=result+wxT("))");
 // wxMessageBox(result,wxT("title"));
wxTextFile txtFile;
wxString Linea;
wxMBConvUTF8 conv;
//(nth 0 (aref *doubleball* 1110))
wxFileOutputStream stream(wxT("doubleball.lisp"));
wxTextOutputStream textOut(stream, wxEOL_UNIX, conv);

textOut.WriteString(result + wxT("\r\n"));
stream.Close();
wxString dir=::wxGetCwd();
BFrame->statusbar->SetStatusText(wxT("write directory:")+dir+wxT("\\doubleball.lisp"), 0);
wxMessageBox(wxT("write ok\n"+dir+wxT("\\doubleball.lisp")),wxT("done"));
}
void GlobalEvtHandler::OnRedBallDistanceHandler(wxCommandEvent& event)
{

wxString SQL=wxEmptyString;
wxString result,tmpres;
DoubleBall* db=new DoubleBall();
wxString term=wxEmptyString;
for(int j=0;j<18;j++)
{
SQL=wxT("SELECT ");
wxString maxrow=wxT("(select max(rowid)-")+wxString::Format(wxT("%d"),j)+wxT(" from _dbhistory)");
wxString nextrow=wxT("(select max(rowid)+1-")+wxString::Format(wxT("%d"),j)+wxT(" from _dbhistory)");
term =wxT("select * from _dbhistory where rowid = ")+nextrow;
db->query((term).char_str());
tmpres=formatDBtoHTML(db,true);
for(int i=1;i<=MAXREDBALL;i++)
{
SQL=SQL+
 maxrow+wxT("-")+wxT("(SELECT rowid from _dbhistory where ")+wxString::Format(wxT("%d"),i)+
               wxT("  in (red1,red2,red3,red4,red5,red6)  and rowid<=")+maxrow+
               wxT(" order by term desc limit 1)")+
               wxString::Format(wxT(" t%0d"),i)+((i<MAXREDBALL)?wxT(","):wxT(""));
}
 db->query((SQL).char_str());
result=result+tmpres
        +
        formatDBtoHTMLTable(db,MAXREDBALL,MAXREDBALL);
}
showHTMLMessage(result);
}
/*
复制数据到粘贴板
*/
void GlobalEvtHandler::OnCopytoClipBoardHander(wxCommandEvent& event)
{
  if (wxTheClipboard->Open())
  {
    wxTheClipboard->SetData( new wxTextDataObject(CurrentPAGE));
    wxTheClipboard->Close();
  }
wxMessageBox(wxT("复制完成!"));
}

void GlobalEvtHandler::OnPagePrintHandler(wxCommandEvent& event)
{
OnCopytoClipBoardHander(event);//copy to clipboard
wxHtmlEasyPrinting* printer = new wxHtmlEasyPrinting(wxT("打印..."));
printer->GetPageSetupData()->SetPaperId(wxPAPER_A4);
printer->GetPageSetupData()->EnableOrientation(true);
printer->GetPageSetupData()->SetMarginBottomRight(wxPoint(1,1));
printer->GetPageSetupData()->SetMarginTopLeft(wxPoint(1,1));
printer->PageSetup();
if(!printer->PreviewText(this->CurrentPAGE))
   {
    wxMessageBox(wxT("打印机错误!"));
    return;
   }
//printer->PrintText(this->CurrentPAGE);

/*
printer=new wxHtmlPrintout(wxT("打印HTML"));
printer->SetMargins(1.0,1.0,1.0,1.0);
printer->SetHtmlText(this->CurrentPAGE);
*/
/*
wxPrinter* wxprinter= new wxPrinter(NULL);
wxprinter->Print(NULL,printer,true);
*/
/*
wxPrintPreview* pp=new wxPrintPreview((wxPrintout*)printer,(wxPrintout*)printer,(wxPrintData*)NULL);
    if (!pp->Ok())
    {
        delete pp;
        wxMessageBox(wxT("There was a problem previewing.\nPerhaps your current printer is not set correctly?"), wxT("Previewing"), wxOK);
        return;
    }
 wxPreviewFrame *frame = new wxPreviewFrame(pp, NULL, wxT("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650));
    frame->Centre(wxBOTH);
    frame->Initialize();
    frame->MakeModal(true);
    frame->Show();
    */
}
//toolbar search button
void GlobalEvtHandler::OnSearchHandler(wxCommandEvent& event)
{
wxString SQL=wxT("select * from _DBHISTORY ");
wxString insm=wxT(" in (red1,red2,red3,red4,red5,red6) ");
//wxString limit=wxT(" limit 0,33");//最多显示100个
wxString limit=wxT(" ");//最多显示100个
wxString where=wxEmptyString;
wxString where1=wxEmptyString;
wxString where2=wxEmptyString;
wxString start=wxEmptyString;
start=searchstartterm->GetValue();
//add for 对偶数分析
wxString findmatch=wxEmptyString;
wxString manualsql =sqltext->GetValue().Trim();

if(endmatch->GetValue().Trim()!=wxEmptyString && startmatch->GetValue().Trim()!=wxEmptyString)
{
 wxArrayString start1=split(startmatch->GetValue().Trim(),wxT(","));
 wxArrayString end1=split(endmatch->GetValue().Trim(),wxT(","));
 int minlength = (start1.GetCount()>end1.GetCount()?end1.GetCount():start1.GetCount());
wxLogMessage(wxT("对偶数 %d"),minlength);
wxString formatstr=wxT("select * from _DBHISTORY where rowid in"
"(select rowid+1 as rowid  from _DBHISTORY where %d in (red1,red2,red3,red4,red5,red6))"
" and  %d in (red1,red2,red3,red4,red5,red6)"
"union "
"select * from _DBHISTORY where rowid in"
"("
"select rowid-1 from _DBHISTORY where rowid in"
"(select rowid+1 as rowid  from _DBHISTORY where %d in (red1,red2,red3,red4,red5,red6))"
" and  %d in (red1,red2,red3,red4,red5,red6)"
")");
wxString tmpstr;
for(int i=0;i<minlength;i++)
{
wxString tmpstr1;
long value1,value2;
start1[i].ToLong(&value1,10);
end1[i].ToLong(&value2,10);
tmpstr1.Printf(formatstr,value1,value2,value1,value2);
if(i<(minlength-1))tmpstr1=tmpstr1+wxT(" union ");
tmpstr= tmpstr+tmpstr1;
}
findmatch=tmpstr;
if(start!=wxEmptyString)findmatch=wxT("select * from (")+findmatch+wxT(") where cast(term as int)>=")+start;
//wxLogMessage(findmatch);
}

if(h_positionStrict->IsChecked())
{
 if(h_comboBox1->GetValue()!=wxEmptyString)where1= wxT(" red1=")+h_comboBox1->GetValue();
 if(h_comboBox2->GetValue()!=wxEmptyString)where1=where1+ (where1!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" red2=")+h_comboBox2->GetValue();
 if(h_comboBox3->GetValue()!=wxEmptyString)where1=where1+ (where1!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" red3=")+h_comboBox3->GetValue();
 if(h_comboBox4->GetValue()!=wxEmptyString)where1=where1+ (where1!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" red4=")+h_comboBox4->GetValue();
 if(h_comboBox5->GetValue()!=wxEmptyString)where1=where1+ (where1!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" red5=")+h_comboBox5->GetValue();
 if(h_comboBox6->GetValue()!=wxEmptyString)where1=where1+ (where1!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" red6=")+h_comboBox6->GetValue();
 if(h_blue_combobox->GetValue()!=wxEmptyString)where1=where1+  (where1!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" blue=")+h_blue_combobox->GetValue();
 if(start!=wxEmptyString)where1=where1+ (where1!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" cast(term as int)>=")+start;

  if(where1!=wxEmptyString)
  where1=wxT(" where ")+where1;
}else
{
 wxString select=wxEmptyString;

 if(h_comboBox1->GetValue()!=wxEmptyString)select=h_comboBox1->GetValue()+insm;
 if(h_comboBox2->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+h_comboBox2->GetValue()+insm;
 if(h_comboBox3->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+h_comboBox3->GetValue()+insm;
 if(h_comboBox4->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+h_comboBox4->GetValue()+insm;
 if(h_comboBox5->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+h_comboBox5->GetValue()+insm;
 if(h_comboBox6->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+h_comboBox6->GetValue()+insm;
 if(h_blue_combobox->GetValue()!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" blue=")+h_blue_combobox->GetValue();
if(start!=wxEmptyString)select=select+ (select!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" cast(term as int)>=")+start;

 if(select!=wxEmptyString)
  where1= wxT(" where ")+select;
}

if(where1!=wxEmptyString && h_follow->IsChecked())// && watchNext->GetValue()==listStype[1]
 {
   where2=wxT(" where rowid in (select rowid+1 as rowid from _DBHISTORY ")+where1+wxT(")");
 }
 if(manualsql !=wxEmptyString  )
 {
   where1 =wxT(" where "+manualsql);
  if(start!=wxEmptyString)where1=where1+ (where1!=wxEmptyString?wxT(" and "):wxEmptyString)+wxT(" cast(term as int)>=")+start;
   if(h_follow->IsChecked())
   {
     where2=wxT(" where rowid in (select rowid+1 as rowid from _DBHISTORY ")+where1+wxT(")");
   }

 }
//::wxGetTextFromUser(wxEmptyString,wxEmptyString,SQL+where1+limit+wxT("...1") );
DoubleBall* db=new DoubleBall();
db->query((SQL+where1+limit).char_str());
h_historywin->SetBackgroundColour(*wxLIGHT_GREY);
wxString result1=formatDBtoHTML(db);
wxString result2=wxEmptyString;
wxString finalSQL;
if(h_watchNext->GetValue()==listStype[1])
  {
//::wxGetTextFromUser(wxEmptyString,wxEmptyString,SQL+where2+limit );
 if(where2!=wxEmptyString)
  {
   db->query((SQL+where2 +limit).char_str());
   result2=formatDBtoHTML(db);
  }
   if(findmatch!=wxEmptyString)
   {
   db->query((findmatch +limit).char_str());
   result2=formatDBtoHTML(db);
   }

  }else if(h_watchNext->GetValue()==listStype[2])
  {
      if(h_follow->IsChecked())
        {
        finalSQL=(SQL+where1)+wxT(" union ")+(SQL+where2);
        }else
        {
         finalSQL=(SQL+where1);
        }
   //if has 对偶数，则跳过这些
   if(findmatch!=wxEmptyString)finalSQL = findmatch;
   db->query((finalSQL+limit).char_str());
    result1=wxT("");
   result2=formatDBtoHTMLGrid(db);
  }else if(h_watchNext->GetValue()==listStype[0])
  {
      if(h_follow->IsChecked())
        {
        finalSQL=(SQL+where1)+wxT(" union ")+(SQL+where2);
        }else
        {
         finalSQL=(SQL+where1);
        }
   db->query((finalSQL +limit).char_str());
   result1=wxT("");
   result2=formatDB2LUOSHU36(db,15);
  }
wxString additional=wxEmptyString;

//add 统计部分
wxString stasql=where1;

 if(where2 !=wxEmptyString)stasql=where2;
//if(where2!=wxEmptyString)
// {
  db->query((SQL+stasql+limit).char_str());
 Statistics* result=statisticsRecords(db);
additional=arrary2string(&result->numberCount[0],MAXREDBALL);
wxString tmp;

tmp.Printf(wxT("最小数字:%02i,最大数字:%02i,记录数目:%04i,显示33"),result->min,result->max,db->nrow);

additional=tmp+wxT("<br>")
+wxT("<br><font color=red>红球出现频率统计:</font>")+arrary2string(&result->numberCount[0],MAXREDBALL)
+wxT("<br><b><font color=blue>篮球出现频率统计:</font></b>")+arrary2string(&result->numberBlueCount[0],MAXBLUEBALL)
+wxT("<br><font color=green><b>红球最大位置出现频率统计:</b></font>")
+arrary2string(&result->numberMaxCount[0],MAXREDBALL)+wxT("<br><font color=green><b>红球最小位置出现频率统计:</b></font>")
+arrary2string(&result->numberMinCount[0],MAXREDBALL)+wxT("<br>")
+wxT("<br><font color=green>连续数字:<b>")+hashmap2html(result->continuum)+wxT("</b></font>");

//  }
wxString formatpage=
                    wxT("<table border=1 ><tr>")
                    wxT("<td VALIGN=top>")+result1+wxT("</td>")
                    wxT("<td VALIGN=top>")+result2+wxT("</td>")
                    wxT("</tr></table>");
BFrame->_CLIPBOARD=wxT("<html><body>")+formatpage+wxT("</body></html>");

this->CurrentPAGE=wxT("<html><body><table><tr><td colspan=35>")+formatpage
  +wxT("</td></tr>")
  +wxT("<tr><td colspan=35>")+additional+wxT("</td></tr>")
  +wxT("</table></body></html>");;

h_historywin->SetPage(CurrentPAGE);
delete db;
}

/*
book1分析入口
*/
void GlobalEvtHandler::startAIAction(wxCommandEvent& event)
{
 long value=55;
if(!termrange->GetValue().ToLong(&value))
{
   value=55;
    termrange->SetValue(wxT("55"));
        }

   BFrame->AIActionWatchTextBox->Clear();
wxString term=termlist->GetValue();
BFrame->AIActionWatchTextBox->AppendText(term+wxT("分析开始于...")+wxNow()+wxT("\n"));
geometryShapeConstruction* gs= new geometryShapeConstruction();
gs->tellMe(term);
//globals
long max1,min1;
doubleball* redball=new doubleball(term);
wxArrayString lessthan10=findLessThanTen(redball->redBall());

int maxright=getRightDistance(redball->redBall());
BFrame->AIActionWatchTextBox->AppendText(wxT("小于10")+arrary2string(lessthan10)
                                         +wxString::Format(wxT(",右段距离:%02d"),maxright)+wxT(",\n"));
//最小
BFrame->AIActionWatchTextBox->AppendText(wxT("小于10猜测:")+arrary2string(guessCouble(lessthan10,maxright))+wxT("\n"));
//最左端
BFrame->AIActionWatchTextBox->AppendText(wxT("最左端猜测:")+arrary2string(guessLessThan10(lessthan10))+wxT("\n"));
}
/*
当下拉选择的时候
*/
void GlobalEvtHandler::comboboxSelected(wxCommandEvent& event)
{
    wxComboBox* cb=wxDynamicCast(event.GetEventObject(),wxComboBox);
    wxString term=cb->GetValue();
   book1infolabel->SetLabel(term+wxT(":")+book1terms[term]);

}
/*
得到最后33期term
*/
redBallHM  GlobalEvtHandler::getTermList(int number,bool reverorder)
{
 redBallHM  result;
DoubleBall* db=new DoubleBall();
 wxString SQL;
 wxString value,term;
 SQL.Printf(wxString(wxT(""))+wxT("select * from _DBHISTORY  ")+(reverorder?wxT(" order by term asc "):wxT(" order by term desc "))+wxT(" limit 0,%02d"),number);
//::wxGetTextFromUser(wxEmptyString,wxEmptyString,SQL);
 db->query(SQL.char_str());
 for(int i=1;i<=db->nrow;i++)
     {
     term=wxString::FromAscii(db->records[i*db->ncol]);
      for( int j=1;j<db->ncol;j++)
        {
          value=value+wxString::FromAscii(db->records[i*db->ncol+j]);
          if(j<db->ncol-1)value=value+wxT(",");
        }
       result[term]=value;
       value=wxEmptyString;
     }
delete db;
 return result;
}
void GlobalEvtHandler::InternetUpdate(wxCommandEvent& event)
{
  wxString pages=wxT("乐彩网站发现数据...");

  BFrame->sqlhtml->SetPage(wxT("<html><body>")+pages+wxT("</body></html>"));
  wxString lastterm=getLastTermOrder();
   // wxString term=FeiCaiTianXia(lastterm);
  wxString  term=LeCaiWang(lastterm);

   if(term==wxEmptyString)
   {
    pages=wxT("从红蓝球霸网站更新....");
    BFrame->sqlhtml->SetPage(wxT("<html><body>")+pages+wxT("</body></html>"));
   term=HongLanQiuBa(lastterm);

   debug(wxT("从红蓝球霸网站更新:")+term);
   BFrame->SQLTextBox->SetValue(term);
       if(term!=wxEmptyString)
       {
        term=term+wxT("<h2><font color=red>必须填上时间 格式:年-月-日</font></h2>");
       }else
       {
        term=wxT("<h2><font color=red>没有发现数据需要更新!!!!</font></h2>");
       }

   }else
   {
    BFrame->SQLTextBox->SetValue(term);
    term=term+wxT("<h2><font color=red>必须填上时间 格式:年-月-日</font></h2>");
   }

  BFrame->sqlhtml->SetPage(wxT("<html><body>最后数据:")+term+wxT("</body></html>"));

}
void GlobalEvtHandler::DestroyDialog(wxCommandEvent& event)
{
 if(h_dialog!=NULL)
 {
  h_dialog->Destroy();
 }
h_dialog=NULL;
}

/*
Save code to database
*/
void GlobalEvtHandler::OnLISPSaveHandler(wxCommandEvent& event)
{
wxString codes = BFrame->LISPCodeBox->GetValue();
wxString title =BFrame->LISPCodeName->GetValue();
if(codes.Trim() == wxEmptyString ||codes == wxEmptyString)return;
if(title.Trim() == wxEmptyString ||title == wxEmptyString)
{
    wxMessageBox(wxT("代码名字不能为空!"));
    return;
}

DoubleBall* db =new DoubleBall();
char * txt = "INSERT INTO _LISPLET(name,codes,flag) VALUES('%q','%q','1')";
char *zSQL = sqlite3_mprintf(txt,(char*)(title.char_str()), (char*)codes.char_str());
db->executeCRUD(zSQL);
sqlite3_free(zSQL);
}

void GlobalEvtHandler::OnLISPDelHandler(wxCommandEvent& event)
{

}
